package com.foreknow.demo12.exer;

/**
 * @author shkstart
 * @create 2021-08-04 9:07
 */

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *  {"aaa","ccc","vvv","nnn","aaa","ccc","vvv","ddd","eee","eee","ddd","ccc","aaa","vvv","nnn"},
 *  * 使用最少的代码统计出每个字符串对象出现的次数
 */
public class Setexer {
    public static void main(String[] args) {
        int num=0;
        Set<String> set=new HashSet<>();
        String[] arr1 = {"aaa", "ccc", "vvv", "nnn", "aaa", "ccc", "vvv", "ddd", "eee", "eee", "ddd", "ccc", "aaa", "vvv", "nnn"};
        for (int i = 0; i < arr1.length; i++) {

            set.add(arr1[i]);
        }
        Iterator<String> iterator = set.iterator();
      while (iterator.hasNext()){
          String next = iterator.next();
          for (int i = 0; i < arr1.length; i++) {

              if(next.equals(arr1[i])){
                  num++;

              }
          }

          System.out.println(next+"-----"+num);
          num=0;
      }





    }


}
